package com.milling.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.milling.common.annotation.Log;
import com.milling.common.core.controller.BaseController;
import com.milling.common.core.domain.AjaxResult;
import com.milling.common.enums.BusinessType;
import com.milling.business.domain.WmsAreaInfo;
import com.milling.business.service.IWmsAreaInfoService;
import com.milling.common.utils.poi.ExcelUtil;
import com.milling.common.core.page.TableDataInfo;

/**
 * 货区设置Controller
 *
 * @author X
 * @date 2025-01-22
 */
@RestController
@RequestMapping("/business/areainfo")
public class WmsAreaInfoController extends BaseController
{
    @Autowired
    private IWmsAreaInfoService wmsAreaInfoService;

    /**
     * 查询货区设置列表
     */
    @PreAuthorize("@ss.hasPermi('business:areainfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsAreaInfo wmsAreaInfo)
    {
        startPage();
        List<WmsAreaInfo> list = wmsAreaInfoService.selectWmsAreaInfoList(wmsAreaInfo);
        return getDataTable(list);
    }

    /**
     * 导出货区设置列表
     */
    @PreAuthorize("@ss.hasPermi('business:areainfo:export')")
    @Log(title = "货区设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsAreaInfo wmsAreaInfo)
    {
        List<WmsAreaInfo> list = wmsAreaInfoService.selectWmsAreaInfoList(wmsAreaInfo);
        ExcelUtil<WmsAreaInfo> util = new ExcelUtil<WmsAreaInfo>(WmsAreaInfo.class);
        util.exportExcel(response, list, "货区设置数据");
    }

    /**
     * 获取货区设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:areainfo:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(wmsAreaInfoService.selectWmsAreaInfoByAreaId(areaId));
    }

    /**
     * 新增货区设置
     */
    @PreAuthorize("@ss.hasPermi('business:areainfo:add')")
    @Log(title = "货区设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsAreaInfo wmsAreaInfo)
    {
        return toAjax(wmsAreaInfoService.insertWmsAreaInfo(wmsAreaInfo));
    }

    /**
     * 修改货区设置
     */
    @PreAuthorize("@ss.hasPermi('business:areainfo:edit')")
    @Log(title = "货区设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsAreaInfo wmsAreaInfo)
    {
        return toAjax(wmsAreaInfoService.updateWmsAreaInfo(wmsAreaInfo));
    }

    /**
     * 删除货区设置
     */
    @PreAuthorize("@ss.hasPermi('business:areainfo:remove')")
    @Log(title = "货区设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(wmsAreaInfoService.deleteWmsAreaInfoByAreaIds(areaIds));
    }
}
